import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Home.vue'

Vue.use(VueRouter)

/**
 * 订单详情页面
 * @param  path 页面路径
 * @param name 页面name值
 */
function orderDetail(path,name) {
  return {
    path:path+'/:order_id',
    name:name,
    component: () => import("../views/public/order-detail/OrderDetail"),
    meta:{
      title:"订单详情"
    }
  }
}

/**
 * 用户地址管理页面
 * @param path
 * @param name
 * @returns {{path: *, component: (function(): *), meta: {title: string}, name: *}}
 */
function takeAddress(path,name){
  return {
    path:path+'/:select',
    name:name,
    component: () => import("../views/public/take-address/TakeAddress"),
    meta:{
      title:"地址管理"
    },
    children:[
      {
        path:path+'/edit/:address_id',
        name:name+'-edit',
        component: () => import("../views/public/take-address/children/edit/Edit"),
        meta:{
          title:"编辑地址"
        }
      }
    ]
  }
}

const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    children:[
        //商品详情
        {
          path:'/goods/:goods_id',
          name:'goods',
          component: () => import("../views/home/children/goods/Goods"),
          meta:{
            title:"商品详情"
          },
          children:[
            //创建订单
            {
              path:'/goods/create/:goods_id',
              name:'create',
              component: () => import("../views/home/children/goods/children/create/Create"),
              meta:{
                title:"创建订单"
              },
              children:[
                orderDetail("/goods/create/order-detail","create-order-detail"),
                takeAddress("/goods/create/take-address","create-take-address")
              ]
            }
          ]
        },
        //订单列表
        {
          path:'/order/list',
          name:'order',
          component: () => import("../views/home/children/order/Order"),
          meta:{
            title:"我的订单"
          },
          children:[
            orderDetail("/order/list/order-detail","home-order-detail")
          ]
        },
        //签到记录
        {
          path:'/record/list',
          name:'record',
          component: () => import("../views/home/children/record/Record"),
          meta:{
            title:"签到记录"
          },
        }
      ]
  }
]

const router = new VueRouter({
  routes
})

export default router
